<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:insert="~{include :: header('分配角色选择用户')}" />
	<th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
	<div class="toolbar" id="toolbar" role="group">
		<form id="formId" class="form-inline">
			<input type="text" class="form-control mr-1" name="searchKey" placeholder="用户名称/手机号码">
			<button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
				<i class="fa fa-search"></i>
				搜索
			</button>
			<button type="button" class="btn btn-default" onclick="$.form.reset()">
				<i class="fa fa-refresh"></i>
				重置
			</button>
		</form>
	</div>
	<table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
		var datas = [[${@dict.getType('sys_normal_disable')}]];
		var prefix = "/role/auth";
		var roleId = [[${role.roleId}]];

		$(function() {
			var options = {
				showSearch: false,
				showRefresh: false,
				showToggle: false,
				showColumns: false,
		        url: prefix + "/selectUser/list.json?roleId="+ [[${role.roleId}]],
		        modalName: "用户",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'managerId',
		            title: '用户ID',
		            visible: false
		        },
				{
					field: 'loginName',
					title: '登录名'
				},
		        {
		            field: 'managerName',
		            title: '用户名称'
		        },
		        {
		            field: 'mobile',
		            title: '手机'
		        },
		        {
		        	field: 'isDisabled',
		        	title: '用户状态',
		        	align: 'center',
		        	formatter: function (value, row, index) {
		        		return $.table.selectDictLabel(datas, value);
		        	}
		        }]
		    };
		    $.table.init(options);
		});

		function submitHandler() {
			table.set();
			var rowss = $('#bootstrap-table').bootstrapTable('getSelections');//行的数据
			if (rowss.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			var userIds ="";
			for(var i=0;i<rowss.length;i++){
				userIds += rowss[i].managerId+",";
			}
			userIds = userIds.substring(0, userIds.lastIndexOf(','));
			var data = { "roleId":roleId, "userIds": userIds};
			$.operate.save(prefix + "/add.json", data);
		}
	</script>
</body>
</html>